package com.lhh.test2;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;

import java.util.Objects;

/**
 * @Auther 虎
 * @Data 2020/4/12 16:55
 * @Version 1.0
 */
@SuppressWarnings("unused")
public class LhhCommandLineRunner implements CommandLineRunner {
    Environment environment;

    //使用构造方法的fang方式,注入Environment
    public LhhCommandLineRunner(Environment environment) {
        this.environment = environment;
    }

    @Override
    public void run(String... args) {
        System.out.println("利用SpringBoot自动装配的CommandLineRunner...");

        //利用random的RandomValuePropertySource产生一个32位随机zi字串
        System.out.println("生成一个随机字符串：".concat(Objects.requireNonNull(environment.getProperty("random.*"))));
    }
}